<html>
<head><meta charset="utf-8"><title>const adapter naming · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html">const adapter naming</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221377045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/221377045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#221377045">(Jan 02 2021 at 00:48)</a>:</h4>
<p>Hey, over the winter break me and a pal have written a const version of <code>Iterator::{combinations, permutations}</code> which uses const generics to infer the K-factor. An example of this in use is this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="p">[</span><span class="n">n1</span><span class="p">,</span><span class="w"> </span><span class="n">n2</span><span class="p">,</span><span class="w"> </span><span class="n">n3</span><span class="p">]</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">5</span><span class="p">).</span><span class="n">combinations</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">println!</span><span class="p">(</span><span class="s">"{}, {}, {}"</span><span class="p">,</span><span class="w"> </span><span class="n">n1</span><span class="p">,</span><span class="w"> </span><span class="n">n2</span><span class="p">,</span><span class="w"> </span><span class="n">n3</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>My question is one about naming: the only other const generic method in the stdlib I know of uses a <code>array_</code> prefix (<code>array_windows</code>). Both <code>combinations</code> and <code>permutations</code> currently don't have a non-const variant in the stdlib. Have people thought about guidelines on naming const generic methods? Should const generic methods always come in pairs?</p>
<p>I don't expect there to be any guideline RFCs or anything, but I imagine at least some folks contributing to libs will have had to think about this before. So figured I'd ask (:</p>



<a name="221384121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/221384121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#221384121">(Jan 02 2021 at 04:52)</a>:</h4>
<p>array_combinations would fit</p>



<a name="221394689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/221394689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#221394689">(Jan 02 2021 at 10:50)</a>:</h4>
<p>It seems fine just as combinations imo</p>



<a name="221395004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/221395004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#221395004">(Jan 02 2021 at 11:01)</a>:</h4>
<p>imo using just <code>combinations</code> if we don't intend to add a non const variant.</p>



<a name="221397591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/221397591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#221397591">(Jan 02 2021 at 12:18)</a>:</h4>
<p>.windows() is a bit special in that it can have an efficient version without the size in the type, because it can give &amp;[T] slices. But that's not the case for .combinations() at all. That one would have to allocate if it doesn't put the size in the type. So just <code>combinations</code> seems fine to me.</p>



<a name="221399239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/221399239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#221399239">(Jan 02 2021 at 13:04)</a>:</h4>
<p>That makes sense, thank you!</p>



<a name="223993698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/const%20adapter%20naming/near/223993698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/const.20adapter.20naming.html#223993698">(Jan 26 2021 at 03:31)</a>:</h4>
<p>do you intend to submit a PR?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>